#include"TwoCoexistingStacks.h"

Double_stack::Double_stack() 
{ 
	top_a = 0;  
	top_b = maxstack - 1; 
}

Error_code Double_stack::push_a(const Stack_entry& item)
{
	if (top_a >= top_b)
		return overflow;
	entry[top_a++] = item;
	return success;
}

Error_code Double_stack::push_b(const Stack_entry& item)
{
	if (top_a >= top_b)
		return overflow;
	entry[top_b--] = item;
	return success;
}

Error_code Double_stack::stacktop_a(Stack_entry& item)const

{
	if (top_a == top_b)
		return underflow;
	item = entry[top_a - 1];
	return success;
}

Error_code Double_stack::stacktop_b(Stack_entry& item)const

{
	if (top_a == top_b)
		return underflow;
	item = entry[top_b + 1];
	return success;
}

bool Double_stack::full()const 
{
	return top_a == top_b;
}

bool Double_stack::empty_a()const 
{ 
	return top_a <= 0;
}

bool Double_stack::empty_b()const 
{ 
	return top_b == maxstack;
}

Error_code Double_stack::pop_a()
{
	if (top_a <= 0)
		return underflow;
	else top_a--;
	return success;
}

Error_code Double_stack::pop_b()
{
	if (top_b >= maxstack)
		return underflow;
	else top_b++;
	return success;
}